<template>
  <div class="app-container calendar-list-container">
    <el-upload
      action=""
      list-type="picture-card"
      :http-request="fileUploads"
      :file-list="fileList"
      :on-remove="handleRemove"
    >
      <i class="el-icon-plus"></i>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
import { getSystemParamter, updateSystemParamter, fileUpload } from '@/api/system'
export default {
  name: 'system_address',
  data () {
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      fileList:[]
    }
  },
  methods: {
    async handleRemove(res){
      const { data } = await updateSystemParamter({
        systemType: 13,
        parameter: res.url.split(this.$uploadUrl)[1],
        del:1
      })
    },
    async fileUploads({file}) {
      try{
        const fd = new FormData()
        fd.append('file', file)
        fd.append('fileName', 'indexPic')
        const res = await fileUpload(fd)
        this.updPicture(res.data)
      } catch(error) {

      }
    },
    async updPicture (file) {
      // console.log(file);
      const { data } = await updateSystemParamter({
        systemType: 13,
        parameter: file
      })
      // this.getParameter()
    },
    // 获取首页轮播图
    async getParameter(){
      const { data } = await getSystemParamter({
        type:13
        })
        if(!data[0].parameter) return
        let parameter = data[0].parameter.split(',')
        this.fileList = []
        parameter.map(item => {
          var obj = {
            name:'banner',
            url:this.$uploadUrl+item
          }
          this.fileList.push(obj)
          
        })
        // console.log(this.fileList);
    },
  },
  created(){
    this.getParameter();
  }
}
</script>

<style>

</style>
